﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Class_KetNoi;

namespace GiaoDien
{
    public partial class uc_HopDong : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_HopDong()
        {
            InitializeComponent();
        }
        KetNoi_HopDong kn = new KetNoi_HopDong();
        public void LoadDuLieu()
        {
            string sql = "select * from tbl_HopDong";
            gridControl1.DataSource = kn.taobang(sql);
        }
        private void uc_HopDong_Load(object sender, EventArgs e)
        {
            kn.connect();
            lbMaHD.Hide();
            txtMaHD.Hide();
            LoadDuLieu();
        }
        public void Nut()
        {
            btnthem.Enabled = false;
            btnsua.Enabled = false;
            btnxoa.Enabled = false;

            btnluu.Enabled = true;
            btnhuy.Enabled = true;
        }
        int flag;
        private void btnthem_Click(object sender, EventArgs e)
        {
            flag = 0;
            Nut();
        }

        private void btnsua_Click(object sender, EventArgs e)
        {
            flag = 1;
            Nut();
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            kn.xoa_HopDong(txtMaHD.Text.Trim());
            LoadDuLieu();
        }

        private void btnluu_Click(object sender, EventArgs e)
        {
            if (flag == 0)
            {
                kn.them_HopDong(txtTenHD.Text ,txtMaNhanVien.Text,date_NgayBatDau.Text,dateNgayKetThuc.Text ,txtLuongCoBan.Text ,cobMaChucVu.Text );
            }
            if (flag == 1)
            {
                kn.sua_HopDong(txtMaHD.Text ,txtTenHD.Text, txtMaNhanVien.Text, date_NgayBatDau.Text, dateNgayKetThuc.Text, txtLuongCoBan.Text, cobMaChucVu.Text);
            }
            LoadDuLieu();
            btnthem.Enabled =true;
            btnsua.Enabled = true;
            btnxoa.Enabled = true;

            btnluu.Enabled = false;
            btnhuy.Enabled = false;
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            txtMaHD.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaloaiHD").ToString();
            txtTenHD.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"TenHD").ToString();
            txtMaNhanVien.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaNV").ToString();
            date_NgayBatDau.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"NgayBatDau").ToString();
            dateNgayKetThuc.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"NgayKetThuc").ToString();
            txtLuongCoBan.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"LuongCB").ToString();
            cobMaChucVu.Text = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MaCV").ToString();
        }
    }
}
